#!/usr/bin/env python
# encoding: utf-8
# @author: liusir
# @file: demo_03.py
# @time: 2022/11/9 9:19 PM

dict_a = {'one':1,'two':2,'three':3}
dict_a.setdefault( 'four',4 ) # 字典中设置默认值的方法
print( dict_a )
dict_a.setdefault( 'one',5 ) # key如果是存在，则不会修改内容
print( dict_a )

dict_b = {'one':[1],'two':2,'three':3}
dict_b.setdefault( 'one' , [] ).append( 5 )  # 如果setdefault遇到 可变的数据类型，可以追加改变数据
print( dict_b )

list_cs = [
	{"学习名称":"python","步骤编号":"step_01","步骤内容":"购买课程/书籍","完成情况":100},
	{"学习名称":"python","步骤编号":"step_02","步骤内容":"搭建python环境","完成情况":100},
    {'学习名称': '做饭', '步骤编号': 'step_01', '步骤内容': '煮饭', '完成情况': 100.0},
    {'学习名称': '做饭', '步骤编号': 'step_02', '步骤内容': '炒菜', '完成情况': 80.0}
]
dict_c = {}
for list_c in list_cs:
    dict_c.setdefault( list_c['学习名称'],[] ).append( list_c )
print( dict_c )

data_list = []
for key,value in dict_c.items():
    one_dict = {}
    one_dict['学习名称'] = key
    one_dict['操作步骤'] = value
    data_list.append( one_dict )
print( data_list )

